a = 7 * 729 ** 543 - 6 * 81 ** 765 - 5 * 9 ** 987 - 20
k = 0
while a > 0:
    if a % 9 == 8:
        k += 1
    a = a // 9
print(k)
